<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>菜品添加</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
</head>
<body>
<div class="container">
    <form action="../upload.do" class="layui-form" lay-filter="formTest" id="addForm" method="post"
          enctype="multipart/form-data">
        <div class="layui-form-item" style="margin-top: 20px">
            <label class="layui-form-label">
                菜名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="foodName" name="foodName" required lay-verify="required"
                       placeholder="请输入菜名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">所属菜系</label>
            <div class="layui-input-block layui-form" lay-filter="foodclass" style="width:190px">
                <select id="select2" name="foodclass" resource lay-verify="required">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                菜品简介
            </label>
            <div class="layui-input-inline">
                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                推荐星级
            </label>
            <div id="rate"></div>
        </div>
        <input id="rate1" name="rate" type="hidden"/><!--隐藏域-->
        <div class="layui-form-item">
            <label class="layui-form-label">
                价格
            </label>
            <div class="layui-input-inline">
                <input type="number" id="price" name="price" min="0.0" step="0.1" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                图片
            </label>
            <div class="layui-input-inline">
                <input type="file" id="image" name="file" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <input type="submit" class="layui-btn" value="保存"/>
        </div>
    </form>
</div>
<script>
    $(function () {
        $("#select2").html("");
        $.post("../findAllFoodClassName.do", function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#select2").append('<option value="' + data[i] + '">' + data[i] + '</option>');
            }
        }, "json")
    })
    layui.use(['form', 'rate', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var rate = layui.rate;
        var layer = layui.layer;
        //渲染
        form.render('select', 'foodclass');
        rate.render({
            elem: '#rate',  //绑定元素
            length: 5,
            text: true,
            setText: function (value) {
                $("#rate1").val(value);
            },
        });
    })
</script>
</body>
</html>